import axios from 'axios';
const service = axios.create({
    baseURL:globalVar.baseURL,
	//baseURL:'http://121.41.76.43:6688',
	//baseURL: 'http://192.168.53.196:6688',
    timeout: 500000000
});

service.interceptors.request.use(
    config => {
		
		let token=localStorage.getItem('shuilixiehui-token')
		let whiteList=['#/login','#/upload']
		
		let onoff=whiteList.indexOf(location.hash)==-1
		
		
        if (token||onoff) {
            config.headers.Authorization = token;
        }else{
			//window.location.href=globalVar.tiaozhuanUrl
		}
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);




service.interceptors.response.use(
    response => {
		let code=''
        let status=response.status
		console.log(status)
		switch(status){
			case 200:
			  code=response.data.code
			  switch(code){
				  case 5:
					globalVar.Message.warning(response.data.message)
					
					//window.location.href=globalVar.tiaozhuanUrl
				  break;
			  }
			break;
			case 401:
			console.log('跳转失败')
			//window.location.href=globalVar.tiaozhuanUrl
			break;
			default:
			break;
		}
		
		return response.data;
    },
    error => {
		if(error.response&&error.response.status==401){
			console.log('跳转失败')
			//window.location.href=globalVar.tiaozhuanUrl
		}
        return Promise.reject(error);
    }
);


export default service













